package com.faya.green.dao.authority;

import com.faya.green.model.Authority;
import com.faya.green.model.web.UserRoleAuthor;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 权限dao层
 */
public interface AuthorityDao {

	/**
	 * 根据主键获取权限
	 * @param id 主键
	 * @return
	 */
	Authority getAuthorityById(String id);

	/**
	 * 更新权限
	 * @param authority
	 */
	void updateAuthority(Authority authority);

	/**
	 * 新增权限
	 * @param authority
	 * @return
	 */
	void addAuthority(Authority authority);

	/**
	 * 获取全部的权限数据
	 * @return
	 */
	@Select("select * from Authority")
	List<Authority> getAuthorList();


	/**
	 * 删除权限
	 * @param authorId 权限ID
	 */
	@Delete("delete from Authority where id = #{id, jdbcType=VARCHAR} ")
	void delAuthor(String authorId);


	/**
	 * 根据权限ID查询出权限
	 * @param roleId 权限ID
	 * @return
	 */
	@Select("select * from Authority where status in ('1','0') and id in (select authorityId from AuthorityRole where status in ('0','1') and roleId = #{roleId, jdbcType=VARCHAR})")
	List<Authority> getAuthorByRoleId(String roleId);


	/**
	 * 根据用户id获取 用户、权限、角色关系(会过滤重复)
	 * @param userId 用户id
	 * @return
	 */
	@Select("select * from user_author_role where uid = #{userId, jdbcType=VARCHAR} group by aboundary" )
	List<UserRoleAuthor> getUserRoleAuthorByUid(String userId);

}